package scrolls;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Map
{

	//	int map[][] = new int[7][10];
	Resources res;

	public Map()
	{
		res = new Resources();
	}

	void mapLevel(int row, int column, int[][] mapLevel)
	{
		res.readLevel("level_" + column + "_" + row, mapLevel, column);
	}

	public static Rectangle map()
	{
		return new Rectangle(29, 55, 800 - 58, 448 - 105);
	}

	void collision(Graphics2D g2d)
	{
		Rectangle map = HUD.mapRect();
		Rectangle mouse = Input.mouseRect();
		if (map.intersects(mouse))
		{
			g2d.draw(HUD.mapRect());
			g2d.setColor(Color.decode("0x815713"));
			g2d.draw(map());
			drawMap(g2d);
		}
	}

	void drawMap(Graphics2D g2d)
	{
		int z = 66;
		int q = 42;
		for (int row = 0; row <= 7; row++)
		{
			for (int column = 0; column <= 10; column++)
			{
				int[][] mapLevel = new int[15][26];
				mapLevel(row, column, mapLevel);
				for (int i = 0; i <= 14; i++)
				{
					for (int j = 0; j <= 25; j++)
					{
						if (mapLevel[i][j] == 0)
							g2d.drawImage(Resources.mapTextures[0], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 1)
							g2d.drawImage(Resources.mapTextures[1], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 2)
							g2d.drawImage(Resources.mapTextures[2], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 3)
							g2d.drawImage(Resources.mapTextures[3], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 4)
							g2d.drawImage(Resources.mapTextures[4], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 5)
							g2d.drawImage(Resources.mapTextures[5], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 6)
							g2d.drawImage(Resources.mapTextures[6], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 7)
							g2d.drawImage(Resources.mapTextures[7], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
						if (mapLevel[i][j] == 8)
							g2d.drawImage(Resources.mapTextures[8], null, j * 3 + (z * column) + 30, i * 3 + (q * row) + 56);
					}
				}
			}
		}
	}

	void drawLevel(Graphics2D g2d)
	{
		int[][] currentLevel = new int[14][25];
		mapLevel(Player.mapRow, Player.mapColumn, currentLevel);

		for (int i = 0; i < currentLevel.length; i++)
		{
			for (int j = 0; j < currentLevel[i].length; j++)
			{
				if (currentLevel[i][j] == 0)
					g2d.drawImage(Resources.textures[0], null, j * 32, i * 32);
				if (currentLevel[i][j] == 1)
					g2d.drawImage(Resources.textures[1], null, j * 32, i * 32);
				if (currentLevel[i][j] == 2)
					g2d.drawImage(Resources.textures[2], null, j * 32, i * 32);
				if (currentLevel[i][j] == 3)
					g2d.drawImage(Resources.textures[3], null, j * 32, i * 32);
				if (currentLevel[i][j] == 4)
					g2d.drawImage(Resources.textures[4], null, j * 32, i * 32);
				if (currentLevel[i][j] == 5)
					g2d.drawImage(Resources.textures[5], null, j * 32, i * 32);
				if (currentLevel[i][j] == 6)
					g2d.drawImage(Resources.textures[6], null, j * 32, i * 32);
				if (currentLevel[i][j] == 7)
					g2d.drawImage(Resources.textures[7], null, j * 32, i * 32);
				if (currentLevel[i][j] == 8)
					g2d.drawImage(Resources.waterAnimation(), null, j * 32, i * 32);
			}
		}
	}
}
